%!
% Copyright (C) 1990 Y&Y, Inc.
% Copyright 2007 TeX Users Group.
% You may freely use, modify and/or distribute this file.

% CHARTINY.PS utility - 

% NOTE: come in here with name of font in string form already on stack

% Print out all characters in given font with BBox outlined
% This version places all 256 characters on FOUR pages

/fontname 1 index def	% save name of font to analyze
cvn /thefont exch def	% convert from string to PS name

/ptsize 48 def 			% size for font to analyse
% /ptsize 20 def		% size for Math Extension

% Is it a math extension font with large BBox ?

/extension false def

fontname (LucidaNewMath-Extension) eq {/extension true def} if
fontname (CMEX10) eq {/extension true def} if
fontname (cmex10) eq {/extension true def} if
fontname (MTEX) eq {/extension true def} if
fontname (EUEX10) eq {/extension true def} if
fontname (euex10) eq {/extension true def} if

extension {/ptsize 20 def} if

/shownumeric false def		% show numeric code
/shownumeric true def		% show numeric code

/usehex false def		% use octal codes
/usehex true def		% use hexadecimal codes

/showmac true def		% show MacIntosh key chords
/showmac false def		% show decimal code

/texfont true def		% show only 0 - 127
/texfont false def		% show 0 - 255

/standardfont true def	% if only range 32 - 255 is needed
/standardfont false def	% 

% NOTE: default (if above both false) is to show 0 - 255

/numfont /Helvetica def  % font for captions
/capfont /Times-Roman def  % font for captions

% *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 

% MacIntosh key chords		S- => shift		O- => option

/mac 256 array def
mac
0 1 255 {1 index exch () put} for
dup 32	( ) put
dup 33	(!) put
dup 34	(") put
dup 35	(#) put
dup 36	($) put
dup 37	(\%) put
dup 38	(&) put
dup 39	(') put
dup 40	(\() put
dup 41	(\)) put
dup 42	(*) put
dup 43	(+) put
dup 44	(,) put
dup 45	(-) put
dup 46	(.) put
dup 47	(/) put
dup 48	(0) put
dup 49	(1) put
dup 50	(2) put
dup 51	(3) put
dup 52	(4) put
dup 53	(5) put
dup 54	(6) put
dup 55	(7) put
dup 56	(8) put
dup 57	(9) put
dup 58	(:) put
dup 59	(;) put
dup 60	(<) put
dup 61	(=) put
dup 62	(>) put
dup 63	(?) put
dup 64	(@) put
dup 65	(A) put
dup 66	(B) put
dup 67	(C) put
dup 68	(D) put
dup 69	(E) put
dup 70	(F) put
dup 71	(G) put
dup 72	(H) put
dup 73	(I) put
dup 74	(J) put
dup 75	(K) put
dup 76	(L) put
dup 77	(M) put
dup 78	(N) put
dup 79	(O) put
dup 80	(P) put
dup 81	(Q) put
dup 82	(R) put
dup 83	(S) put
dup 84	(T) put
dup 85	(U) put
dup 86	(V) put
dup 87	(W) put
dup 88	(X) put
dup 89	(Y) put
dup 90	(Z) put
dup 91	([) put
dup 92	(\\) put
dup 93	(]) put
dup 94	(^) put
dup 95	(_) put
dup 96	(`) put
dup 97	(a) put
dup 98	(b) put
dup 99	(c) put
dup 100	(d) put
dup 101	(e) put
dup 102	(f) put
dup 103	(g) put
dup 104	(h) put
dup 105	(i) put
dup 106	(j) put
dup 107	(k) put
dup 108	(l) put
dup 109	(m) put
dup 110	(n) put
dup 111	(o) put
dup 112	(p) put
dup 113	(q) put
dup 114	(r) put
dup 115	(s) put
dup 116	(t) put
dup 117	(u) put
dup 118	(v) put
dup 119	(w) put
dup 120	(x) put
dup 121	(y) put
dup 122	(z) put
dup 123	({) put
dup 124	(|) put
dup 125	(}) put
dup 126	(~) put
dup 128	(O-u A) put
dup 129	(S-O-A) put
dup 130	(S-O-C) put
dup 131	(O-e E) put
dup 132	(O-n N) put
dup 133	(O-u O) put
dup 134	(O-u U) put
dup 135	(O-e a) put
dup 136	(O-` a) put
dup 137	(O-i a) put
dup 138	(O-u a) put
dup 139	(O-n a) put
dup 140	(O-a) put
dup 141	(O-c) put
dup 142	(O-e e) put
dup 143	(O-` e) put
dup 144	(O-i e) put
dup 145	(O-u e) put
dup 146	(O-e i) put
dup 147	(O-` i) put
dup 148	(O-i i) put
dup 149	(O-u i) put
dup 150	(O-n n) put
dup 151	(O-e o) put
dup 152	(O-` o) put
dup 153	(O-i o) put
dup 154	(O-u o) put
dup 155	(O-n o) put
dup 156	(O-e u) put
dup 157	(O-` u) put
dup 158	(O-i u) put
dup 159	(O-u u) put
dup 160	(O-t) put
dup 161	(S-O-*) put
dup 162	(O-4) put
dup 163	(O-3) put
dup 164	(O-6) put
dup 165	(O-8) put
dup 166	(O-7) put
dup 167	(O-s) put
dup 168	(O-r) put
dup 169	(O-g) put
dup 170	(O-2) put
dup 171	(O-e) put
dup 172	(O-u) put
dup 173	(O-=) put
dup 174	(S-O-') put
dup 175	(S-O-O) put
dup 176	(O-5) put
dup 177	(S-O-+) put
dup 178	(O-,) put
dup 179	(O-.) put
dup 180	(O-y) put
dup 181	(O-m) put
dup 182	(O-d) put
dup 183	(O-w) put
dup 184	(S-O-P) put
dup 185	(O-p) put
dup 186	(O-b) put
dup 187	(O-9) put
dup 188	(O-0) put
dup 189	(O-z) put
dup 190	(O-') put
dup 191	(O-o) put
dup 192	(S-O-?) put
dup 193	(O-1) put
dup 194	(O-l) put
dup 195	(O-v) put
dup 196	(O-f) put
dup 197	(O-x) put
dup 198	(O-j) put
dup 199	(O-\\) put
dup 200	(S-O-|) put
dup 201	(O-;) put
dup 202	(O-space) put
dup 203	(O-` A) put
dup 204	(O-n A) put
dup 205	(O-n O) put
dup 206	(S-O-Q) put
dup 207	(O-q) put
dup 208	(O--) put
dup 209	(S-O-_) put
dup 210	(O-[) put
dup 211	(S-O-{) put
dup 212	(O-]) put
dup 213	(S-O-}) put
dup 214	(O-/) put
dup 215	(O-S-V) put
dup 216	(O-u y) put
dup 217	(S-O-`) put
dup 218	(S-O-!) put
dup 219	(S-O-@) put
dup 220	(S-O-#) put
dup 221	(S-O-$) put
dup 222	(S-O-%) put
dup 223	(S-O-^) put
dup 224	(S-O-&) put
dup 225	(S-O-\() put
dup 226	(S-O-\)) put
dup 227	(S-O-W) put
dup 228	(S-O-R) put	% (S-O-E) System 6
dup 229	(O-i A) put	% (S-O-M) System 7 or (S-O-R) System 6
dup 230	(O-i E) put	% (S-O-T)
dup 231 (O-e A) put	% (S-O-Y)
dup 232	(O-u E) put	% (S-O-U)
dup 233	(O-` E) put	% (S-O-I)
dup 234	(O-e I) put	% (S-O-S)
dup 235	(O-i I) put	% (S-O-D)
dup 236 (O-u I) put	% (S-O-F)
dup 237 (O-` I) put	% (S-O-G)
dup 238	(O-e O) put	% (S-O-H)
dup 239 (O-i O) put	% (S-O-J)
dup 240	(S-O-K) put
dup 241	(O-` O) put	% (S-O-L)
dup 242	(O-e U) put	% (S-O-:)
dup 243	(O-i U) put	% (S-O-Z)
dup 244	(O-` U) put	% (S-O-X)
dup 245	(S-O-B) put
dup 246	(S-O-I) put	% (S-O-N) System 6
dup 247	(S-O-N) put	% (S-O-M) System 6
dup 248	(S-O-<) put
dup 249	(S-O->) put
dup 250	(S-O-H) put
dup 251	(S-O-K) put
dup 252 (S-O-Z) put % System 7
dup 253 (S-O-G) put % System 7
dup 254 (S-O-X) put % System 7
dup 255 (S-O-T) put % System 7
pop % mac

% *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 

/smltextsize 8 def 	% size of font for charname caption

/smlsize 9 def 	% size of font for numeric captions

/lrgsize 12 def % size of font for font name top left

/font{findfont exch scalefont} bind def % size font

/bigfont ptsize thefont font def

/smlfont smlsize numfont font def

/smltextfont smltextsize capfont font def

/lrgfont lrgsize numfont font def

/eps ptsize 20 div def		% size of tick marks

/inch{72 mul} bind def

/linewidth .24 def		% thickness of ticks and dashed line

/xstart .75 inch def /ystart 11 .75 sub inch def % top left

/getencoding {			% char specified by number
	thefont findfont /Encoding get exch get} bind def

/box{ % dx dy
	1 index 0 rlineto 0 1 index rlineto 
	exch neg 0 rlineto neg 0 exch rlineto
	closepath } bind def

/fillbox{ % xs ys xe ye
	newpath 3 index 3 index moveto
	2 index sub exch 3 index sub exch 4 2 roll pop pop	
	box
	fill} bind def

/strokebox{ % xs ys xe ye
% see whether sticks out more below base line than above
	dup ypos sub 3 index ypos sub neg le /flipped exch def
% see whether sticks out only a little below baseline
	2 index ypos sub neg 10 le {/flipped false def} if
	newpath 3 index 3 index moveto
	2 index sub exch 3 index sub exch 4 2 roll pop pop	
	box
	stroke} bind def

/tick { % make tick mark at character origin and next origin
	eps 0 rmoveto eps neg dup add 0 rlineto
	eps eps rmoveto 0 eps neg dup add rlineto stroke} bind def

/char 1 string def % place for single characters

/drawchar{ % char xpos ypos
  char exch 0 exch put  /ypos exch def /xpos exch def 
  bigfont setfont
  [] 0 setdash   xpos ypos moveto tick
  char stringwidth 
  pop xpos add ypos moveto tick
  xpos ypos moveto   char false charpath   flattenpath   pathbbox
  [3] 0 setdash   strokebox
  xpos ypos moveto   char show} bind def 

/upnumdy 18 def /upworddy 8 def 
/downnumdy -24 def /downworddy -34 def
/octaldx 20 def /hexdx 29 def

/showchar{ % xo yo char
  /num exch def  /ypos exch def /xpos exch def 	
  xpos ypos num  drawchar % moved here
  smlfont setfont
  xpos ypos flipped{upnumdy}{downnumdy}ifelse add moveto % ptsize .5 mul 
  showmac
  {mac num get show}
  {num =string cvs show}
  ifelse
  shownumeric
  {usehex
  {xpos hexdx add ypos flipped{upnumdy}{downnumdy}ifelse add moveto 
  	(") show num 16 =string cvrs show}
  {xpos octaldx add ypos flipped{upnumdy}{downnumdy}ifelse add moveto 
      	(\\) show num 8 =string cvrs show}
  ifelse
  }if
  xpos ypos flipped{upworddy}{downworddy}ifelse add moveto % ptsize .7 mul 
  smltextfont setfont
  num getencoding dup /.notdef ne {=string cvs show}{pop} ifelse
} bind def

/columns 8 def /rows 8 def

/hspace 8.5 2 sub inch columns .75 sub div def % column separation
/vspace 11 2 sub inch rows .5 sub div def  % row separation

/caption{ % insert font name at top of page
xstart ystart .25 inch add moveto
lrgfont setfont
fontname show
extension {( ) show ((reduced scale)) show} if
} bind def

/page1{
/charstart 32 def
caption
linewidth setlinewidth
0 1 rows 1 sub {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index columns mul 3 index add charstart add
       showchar pop} for pop
       } for
showpage
} bind def

/page2{
/charstart 96 def
caption
linewidth setlinewidth
0 1 3 {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index columns mul 3 index add charstart add
       showchar pop} for pop
       } for
/charstart 160 def
4 1 7 {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index 4 sub columns mul 3 index add charstart add
       showchar pop} for pop
       } for
showpage
} bind def

/page3{
/charstart 192 def
caption
linewidth setlinewidth
0 1 rows 1 sub {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index columns mul 3 index add charstart add
       showchar pop} for pop
       } for
showpage
} bind def

/pagea{
/charstart 0 def
caption
linewidth setlinewidth
0 1 rows 1 sub {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index columns mul 3 index add charstart add
       showchar pop} for pop
       } for
showpage
} bind def

/pageb{
/charstart 64 def
caption
linewidth setlinewidth
0 1 rows 1 sub {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index columns mul 3 index add charstart add
       showchar pop} for pop
       } for
showpage
} bind def

/pagec{
/charstart 128 def
caption
linewidth setlinewidth
0 1 rows 1 sub {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index columns mul 3 index add charstart add
       showchar pop} for pop
       } for
showpage
} bind def

/paged{
/charstart 192 def
caption
linewidth setlinewidth
0 1 rows 1 sub {
0 1 columns 1 sub {dup hspace mul xstart add 
       2 index 0.5 add vspace mul neg ystart add 
       3 index columns mul 3 index add charstart add
       showchar pop} for pop
       } for
showpage
} bind def

% *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 

standardfont { 		 % use for Adobe fonts (omit 0 - 31 and 128 -159)
page1 page2 page3 } if

texfont{ 		 % use for TeX CM fonts (0 - 127 only)
pagea pageb } if

% pagec paged

texfont not standardfont not and { % use for full fonts (0 - 256)
pagea pageb pagec paged 
} if


